#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDebug>
#include<QPushButton>
#include<QColorDialog>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    resize(500,500);
    QWidget*bgWidget=new QWidget(this);
    bgWidget->setGeometry(0,0,500,500);
    bgWidget->lower();
    QPushButton*button=new QPushButton("颜色选择按钮",this);
    QColorDialog*cdlg=new QColorDialog(this);
    connect(button,&QPushButton::clicked,[=](){
       //设置颜色对话框，并设置默认颜色为红色
        QColor color=cdlg->getColor(QColor(255,255,255));//红绿蓝;
        qDebug()<<"r"<<color.red();
        qDebug()<<"r"<<color.green();
        qDebug()<<"r"<<color.blue();
        QString style=QString("background-color:rgba(%1,%2,%3,255);").arg(color.red())
                                                                     .arg(color.green())
                                                                     .arg(color.blue());
//        this->setStyleSheet(style);
          bgWidget->setStyleSheet(style);
//        cdlg->setCurrentColor(QColor(255,255,255));
//        cdlg->open();
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}

